﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xms.Core.Context;
using Xms.CRM.Data;
using Xms.CRM.Domain;
using Xms.Data.Provider;

namespace Xms.CRM
{
    public class StudentService : IStudentService
    {
        private readonly IStudentRepository _iStudentRepository;

        public StudentService(IStudentRepository iStudentRepository
            )
        {
            _iStudentRepository = iStudentRepository;
        }

        public Guid Create(Student entity)
        {
            return _iStudentRepository.CreateEntity(entity);
        }

        public bool CreateMany(List<Student> entitys)
        {
            return _iStudentRepository.CreateMany(entitys);
        }

        public bool Update(Student entity)
        {
            return _iStudentRepository.Update(entity);
        }

        public bool Update(Func<UpdateContext<Student>, UpdateContext<Student>> context)
        {
            var ctx = context(UpdateContextBuilder.Build<Student>());
            return _iStudentRepository.Update(ctx);
        }

        public Student FindById(Guid id)
        {
            return _iStudentRepository.FindById(id);
        }

        public bool DeleteById(Guid id)
        {
            return _iStudentRepository.DeleteById(id);
        }

        public bool DeleteById(List<Guid> ids)
        {
            var flag = true;
            foreach (var id in ids)
            {
                flag = this.DeleteById(id);
            }
            return flag;
            //return _repository.DeleteById(ids);
        }

        public PagedList<Student> QueryPaged(Func<QueryDescriptor<Student>, QueryDescriptor<Student>> container)
        {
            QueryDescriptor<Student> q = container(QueryDescriptorBuilder.Build<Student>());

            return _iStudentRepository.QueryPaged(q);
        }

        public List<Student> Query(Func<QueryDescriptor<Student>, QueryDescriptor<Student>> container)
        {
            QueryDescriptor<Student> q = container(QueryDescriptorBuilder.Build<Student>());

            return _iStudentRepository.Query(q)?.ToList();
        }
    }
}
